#include "traversalmode.h"
#include "ui_traversalmode.h"

TraversalMode::TraversalMode(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::TraversalMode)
{
    ui->setupUi(this);

    // 更改描述
    ui->OtherTraversalEdit->setPlaceholderText("前序遍历");
    ui->MidTraversalEdit->setPlaceholderText("中序遍历");

    ui->InputButton->setText("字符输入");

    ui->IsPrevCheckBox->setText("是否使用前序遍历");
    ui->IsPrevCheckBox->setChecked(true);
}

TraversalMode::~TraversalMode()
{
    delete ui;
}

void TraversalMode::on_IsPrevCheckBox_clicked()
{
    if (ui->IsPrevCheckBox->isChecked() == false) {
        ui->OtherTraversalEdit->setPlaceholderText("后序遍历");
    }
    else {
        ui->OtherTraversalEdit->setPlaceholderText("前序遍历");
    }
}

void TraversalMode::on_InputButton_clicked()
{
    if (ui->OtherTraversalEdit->text().length() == 0 || ui->MidTraversalEdit->text().length() == 0) {
        return;
    }
    Painter *painter = new Painter(BuildBinaryTreeByTraversal(ui->OtherTraversalEdit->text(), ui->MidTraversalEdit->text(), ui->IsPrevCheckBox->isChecked()));
    painter->show();
}
